from pydantic import BaseModel, Field, validator
from typing import Optional, List

class LineBase(BaseModel):
    lineName: str = Field(..., description="产线名称")
    status: str = Field(..., description="产线状态")
    describe: Optional[str] = Field(None, description="产线描述")

    @validator("status")
    def status_valid(cls, v):
        if v not in ("active", "inactive", "maintenance"):
            raise ValueError("status只能为active、inactive或maintenance")
        return v

class LineCreate(LineBase):
    lineId: str = Field(..., description="产线编号")

class LineUpdate(BaseModel):
    lineName: Optional[str] = None
    status: Optional[str] = None
    describe: Optional[str] = None

    @validator("status")
    def status_valid(cls, v):
        if v is not None and v not in ("active", "inactive", "maintenance"):
            raise ValueError("status只能为active、inactive或maintenance")
        return v

class LineDetail(LineBase):
    lineId: str
    createdBy: Optional[str] = Field(None, description="创建人(后端自动生成)")
    createdAt: Optional[str] = Field(None, description="创建时间(后端自动生成)")
    updatedBy: Optional[str] = Field(None, description="更新人(后端自动生成)")
    updatedAt: Optional[str] = Field(None, description="更新时间(后端自动生成)")
    workbenches: Optional[List[dict]] = None  # 可用 Workbench schema 替换

class LineWorkbenchUpdate(BaseModel):
    benches: List[dict]  # [{"benchId":..., "prevBench":..., "nextBench":...}]
